/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.deployment.command;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.CollaborationUse;
import org.eclipse.uml2.uml.CommunicationPath;

import com.cea.papyrus.core.commands.connection.ConnectionReconnectCommand;
import com.cea.papyrus.core.commands.connection.RoleBindingReconnectCommand;
import com.cea.papyrus.diagraminterchange2.di2.GraphEdge;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;
import com.cea.papyrus.diagraminterchange2.di2.Uml1SemanticModelBridge;

/**
 * 
 */
public class ConnectionReconnectCommandFactory {
	
	/**
	 * Singleton instance of the factory.
	 */
	public static ConnectionReconnectCommandFactory eINSTANCE = new ConnectionReconnectCommandFactory();


	/**
	 * 
	 * 
	 * @param newEndpoint 
	 * @param end 
	 * @param conn 
	 * @param newLocation 
	 * 
	 * @return 
	 */
	public ConnectionReconnectCommand getConnectionReconnectCommand(GraphEdge conn, GraphElement newEndpoint, Point newLocation, int end){

		java.lang.Class eClass =null;
		if( conn.getSemanticModel()!=null){
			if(((Uml1SemanticModelBridge)conn.getSemanticModel()).getElement()!=null){
				eClass=((Uml1SemanticModelBridge)conn.getSemanticModel()).getElement().getClass().getInterfaces()[0];
			}
			else return null;
		}
		if(eClass == null) {
			return new ConnectionReconnectCommand(conn,newEndpoint,newLocation, end);
		}
		if (eClass.equals(CollaborationUse.class)){
			return new RoleBindingReconnectCommand(conn,newEndpoint,newLocation, end);
		}	
		if(eClass.equals(Association.class)){
			return new AssociationReconnectCommand(conn,newEndpoint,newLocation, end);
		}
		if(eClass.equals(CommunicationPath.class)){
			return new CommunicationPathReconnectCommand(conn,newEndpoint,newLocation, end);
		}

		return new ConnectionReconnectCommand(conn,newEndpoint,newLocation, end);

	}
}